package com.vodone.v1pin.userInfo.delegate
{
	import com.vodone.v1pin.index.vo.PicVO;
	import com.vodone.v1pin.userInfo.vo.CategoryVO;
	import com.vodone.v1pin.userInfo.vo.CouponVO;
	
	import mx.collections.ArrayCollection;

	public class CouponUtil
	{
		public static function getCouponListFromObj(obj:Object):ArrayCollection
		{
			var list:ArrayCollection = new ArrayCollection();
			if(obj && obj is Array)
			{
				var arr:Array = obj as Array;
				if(arr && arr.length > 0)
				{
					for(var i:int = 0; i< arr.length ; i++)
					{
						list.addItem(getCouponItem(arr[i]));
					}
				}
			}
			return list;
		}
		
		public static function getCouponItem(obj:Object):CouponVO
		{
			var item:CouponVO = new CouponVO();
			if(obj)
			{
				if(obj.hasOwnProperty("couponNum"))
				{
					item.couponCode = obj["couponNum"];
				}
				if(obj.hasOwnProperty("couponCode"))
				{
					item.couponCode = obj["couponCode"];
				}
				if(obj.hasOwnProperty("date"))
				{
					item.date = obj["date"];
				}
				if(obj.hasOwnProperty("explain"))
				{
					item.explain = obj["explain"];
				}
				if(obj.hasOwnProperty("money"))
				{
					item.money = obj["money"];
				}
				if(obj.hasOwnProperty("rule"))
				{
					item.rule = obj["rule"];
				}
				if(obj.hasOwnProperty("type"))
				{
					item.type = obj["type"];
				}
				if(obj.hasOwnProperty("scope"))
				{
					item.scope = obj["scope"];
				}
				if(obj.hasOwnProperty("isProduct"))
				{
					item.isProduct = obj["isProduct"];
				}
				if(obj.hasOwnProperty("itemID"))
				{
					item.itemID = obj["itemID"];
				}
			}
			return item;
		}
		
		public static function getCouponTypesFromObj(obj:Object):ArrayCollection
		{
			var list:ArrayCollection = new ArrayCollection();
			if(obj && obj is Array)
			{
				var arr:Array = obj as Array;
				if(arr && arr.length > 0)
				{
					for(var i:int = 0; i< arr.length ; i++)
					{
						list.addItem(getCouponTypesItem(arr[i]));
					}
				}
			}
			return list;
		}
		public static function getCouponTypesItem(obj:Object):CategoryVO
		{
			var item:CategoryVO = new CategoryVO();
			if(obj)
			{
				if(obj.hasOwnProperty("id"))
				{
					item.id = obj["id"];
				}
				if(obj.hasOwnProperty("name"))
				{
					item.name = obj["name"];
				}
				if(obj.hasOwnProperty("Parentname"))
				{
					item.Parentname = obj["Parentname"];
				}
				if(obj.hasOwnProperty("Firstname"))
				{
					item.Firstname = obj["Firstname"];
				}
			}
			return item;
		}
		
		public static function getCouponProductListFromObj(obj:Object):Array
		{
			var list:Array = new Array();
			if(obj && obj is Array)
			{
				var arr:Array = obj as Array;
				if(arr && arr.length > 0)
				{
					for(var i:int = 0; i< arr.length ; i++)
					{
						list.push(getCouponProductItem(arr[i]));
					}
				}
			}
			return list;
		}
		public static function getCouponProductItem(obj:Object):PicVO
		{
			var item:PicVO = new PicVO();
			if(obj)
			{
				if(obj.hasOwnProperty("proID"))
				{
					item.proId = obj["proID"];
				}
				if(obj.hasOwnProperty("prodouctCode"))
				{
					item.id = obj["prodouctCode"];
				}
				if(obj.hasOwnProperty("name"))
				{
					item.name = obj["name"];
				}
				if(obj.hasOwnProperty("price"))
				{
					item.price = obj["price"];
				}
				if(obj.hasOwnProperty("v1Price"))
				{
					item.v1pinPrice = obj["v1Price"];
				}
				if(obj.hasOwnProperty("url"))
				{
					item.url = obj["url"];
				}
				if(obj.hasOwnProperty("discripte"))
				{
					item.discripte = obj["discripte"];
				}
				if(obj.hasOwnProperty("subApp"))
				{
					item.subApp = obj["subApp"];
				}
			}
			return item;
		}
		public static function getFormatData(list:Array , count:int ):Array
		{
			var result:Array = [];
			if(list && list.length > 0 && count > 0)
			{
				var dataLen:int = list.length;
				var len:int = dataLen / count ;
				if( list.length % count != 0 )
				{
					len++;
				}
				for(var i:int = 0 ;i < len ; i++)
				{
					var obj:Array = [];
					for(var j:int = 0 ; j < count ; j++)
					{
						if( (i * count + j) < dataLen)
						{
							obj.push(list[i * count + j]);
						}
						else
						{
							obj.push( new PicVO() );
						}
					}
					result.push(obj);
				}
			}
			return result;
		}
	}
}